// 用于保存辅助工具类的函数
// 复用封函数，变化该参数

// 获取单个DOM节点
function getEle(selector) {
    return document.querySelector(selector)
}
// 获取多个DOM节点
function getEleAll(selector) {
    return document.querySelectorAll(selector)
}

//封装遮罩层
function displayMask() {
    //遮罩层
    let applyBtns = getEleAll('#apiContent li a')
    //遍历数组集合
    applyBtns.forEach(function (v) {
        //点击事件
        v.addEventListener('click', function () {
            getEle('#mask').style.display = 'block';
        })
    })
    //点击遮罩层 让遮罩层消失
    getEle('#mask').addEventListener('click', function () {
        getEle('#mask').style.display = 'none';
    })
    //冒泡 绑定点击事件
    getEle('#modal-box').addEventListener('click', function (e) {
        e.stopPropagation();//阻止冒泡
    })
}

//封装img 跳转到详情页
function imgHref() {
    //跳转
    let imgs = getEleAll('#apiContent li img')
    imgs.forEach(function (v) {
        v.addEventListener('click', function () {
            //点击跳转方法
            window.location.href = 'apiDatail.html'
        })
    })
}


function tab(selector1, className1, selector2, className2) {
    let menulis = getEleAll(selector1)
    let cont = getEleAll(selector2)

    menulis.forEach(function (v, i) {
        v.addEventListener('click', function () {
            menulis.forEach(function (v, i) {
                v.classList.remove(className1)

                if (cont.length != 0) {
                    //清除所有div标签上面的on
                    cont[i].classList.remove(className2)
                }

            })
            //给当前li添加类名active
            this.classList.add(className1)
            
            if (cont.length != 0) [
                //利用索引让li联系到div
                cont[i].classList.add(className2)
            ]

        })
    })

}




function checkUser(val){
    return /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/.test(val)
}



function checkPwd(val){
    return  /^[a-zA-Z]\w{5,17}$/.test(val)
}




